﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using System.Data;
using System.Data.SQLite;

public partial class SaleInfo_ThisMonth : UDCPage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            RentDataBind();
            G2SaleDataBind();
            G3SaleDataBind();
            WIFISaleDataBind();
            KDSaleDataBind();
            GHSaleDataBind();
        }
    }

    private void RentDataBind()
    {
        string sqlstr = @"select dname as 发展渠道,count(distinct serviceid) as 终端用户数
                          from ud_depart_t t1
                          left join ud_developer_t t2  
                            on t1.did = t2.did   
                           and t2.ifvalid = 1 
                          left join (select * from ud_saleinfo_t
                                      where date(saledate) between date('now','start of month')
                                                               and date('now','start of month','+1 month','-1 day')                                        
                                        and isaudit = 1
                                    ) t3  
                            on t2.dvid = t3.dvid
                         where ismanage = 0 
                         group by dname 
                         order by count(distinct serviceid) desc";
        DataSet ds = SQLiteHelper.ExecuteDataset(sqlstr, null);
        RentSales.DataSource = ds;
        RentSales.DataBind();
        LRentCount.Text = "（" + ds.Tables[0].Compute("sum(终端用户数)", "true").ToString() + "）";
    }

    private void G2SaleDataBind()
    {
        UDWS.Service us = new UDWS.Service();
        DataSet ds = us.Get2GCount(System.DateTime.Now.ToString("yyyyMM"));
        G2Sales.DataSource = ds;
        G2Sales.DataBind();
        G2Count.Text = "（" + ds.Tables[0].Compute("sum(单卡2G用户数)", "true").ToString() + "）";
    }

    private void G3SaleDataBind()
    {
        UDWS.Service us = new UDWS.Service();
        DataSet ds = us.Get3GCount(System.DateTime.Now.ToString("yyyyMM"));
        G3Sales.DataSource = ds;
        G3Sales.DataBind();
        G3Count.Text = "（" + ds.Tables[0].Compute("sum(单卡3G用户数)", "true").ToString() + "）";
    }


    private void WIFISaleDataBind()
    {
        UDWS.Service us = new UDWS.Service();
        DataSet ds = us.GetWifiCount(System.DateTime.Now.ToString("yyyyMM"));
        WIFISales.DataSource = ds;
        WIFISales.DataBind();
        NICCount.Text = "（" + ds.Tables[0].Compute("sum(无线网卡用户数)", "true").ToString() + "）";
    }

    private void KDSaleDataBind()
    {
        UDWS.Service us = new UDWS.Service();
        DataSet ds = us.GetKDCount(System.DateTime.Now.ToString("yyyyMM"));
        KDSales.DataSource = ds;
        KDSales.DataBind();
        KDCount.Text = "（" + ds.Tables[0].Compute("sum(宽带用户数)", "true").ToString() + "）";
    }

    private void GHSaleDataBind()
    {
        UDWS.Service us = new UDWS.Service();
        DataSet ds = us.GetGHCount(System.DateTime.Now.ToString("yyyyMM"));
        GHSales.DataSource = ds;
        GHSales.DataBind();
        GHCount.Text = "（" + ds.Tables[0].Compute("sum(固话用户数)", "true").ToString() + "）";
    }
}